- /* sfmredc.cpp by K.Tsuru */
- // function ID = 701 DRADIX
- /*************************************
- SFraction class
- It provides the reduction of fraction.
- **************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- #if REDUCE_SIZE
- static const uint initReduceSize = 512; //initial value of "reduceSize"
- uint SFraction::reduceSize = initReduceSize;
- bool SFraction::reduceStepByStep = true;
-
- void SFraction::reduce(bool must){
- #else
- void SFraction::reduce(){
- #endif
-
- if( !num.Sign(701) ){ SetZero(); return; } //denominator=0
- if( num.IsOne() || den.IsOne() ) reduceDone = true; //denominator or numerator=1
- if( reduceDone == true ) return;
-
- // reduceDone = FALSE
- //To reduce as late as possible It divides by 2^b*R^r.
- if( !(num[0] % 2u) && !(den[0] % 2u) ) ReduceByPow2Rdx(num, den);
- #if REDUCE_SIZE
- if( !must && ( max( num.Head(), den.Head() ) < ReduceSize() )) return;
- #endif
- //reduction
- SLong d = gcdL(num, den); // d > 0
- num /= d; den /= d;
- reduceDone = true;
-
- #if REDUCE_SIZE
- /*
- When the calculation of large figures continues inspite of reduction,
- it enlarges the value of "reduceSize".
- */
- uint rds = min(num.Head(), den.Head()) +1u;
- if(rds > ReduceSize()) SetReduceSize( min(4u*rds, num.MaxSize()) );
- else SetReduceSize(initReduceSize);
- #endif
- }
sfmredc.cpp : last modifiled at 2017/10/23 10:04:49(1,334 bytes)
created at 2015/12/22 16:07:29
The creation time of this html file is 2017/10/23 11:28:46 (Mon Oct 23 11:28:46 2017).